package com.wbt.redisson;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RSet;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import java.util.concurrent.TimeUnit;

public class TestLock {


    public static void main(String[] args) {
        RedissonClient redissonClient = getRedisson();
        redissonClient.getSet("Test_redis").add("scccss");
        RSet<String> test_redis = redissonClient.getSet("Test_redis");

        //System.out.println( test_redis);

        redissonClient.getBucket("test_srt").set("dfefdfdf");

        System.out.println(redissonClient.getBucket("test_srt").get());

        RLock test_lock = redissonClient.getLock("Test_Lock_fdv43f4g45t3");
        test_lock.lock(30 * 1000, TimeUnit.MILLISECONDS);
       // test_lock.unlock();


       // redissonClient.getMultiLock(test_lock);

        redissonClient.shutdown();

    }

    private static RedissonClient getRedisson(){
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://192.168.172.201:6379");

        //  哨兵模式config.useSentinelServers().setMasterName("mymaster").setPassword("web2017").addSentinelAddress("***(哨兵IP):26379", "***(哨兵IP):26379", "***(哨兵IP):26380");
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
